package frontend.pages.admin.legalholiday;

import backend.model.other.LegalHoliday;
import backend.service.other.LegalHolidayService;
import frontend.core.TimeTrackingWebApplication;
import frontend.model.admin.LegalHolidayUIModel;
import frontend.pages.admin.base.AbstractManagingPage;
import org.apache.wicket.markup.html.panel.Panel;
import org.wicketstuff.annotation.mount.MountPath;

import java.util.Calendar;
import java.util.List;

@MountPath("legalHoliday")
public class LegalHolidayManagingPage extends AbstractManagingPage<LegalHoliday> {

    public LegalHolidayManagingPage() {
        super("pages.admin.legalHoliday.title", "contextualHelp.admin.legalHoliday.text");
    }
    @Override
    protected String getAddPanelTitleKey() {
        return "pages.admin.legalHoliday.add.title";
    }

    @Override
    protected String getEditPanelTitleKey() {
        return "pages.admin.legalHoliday.edit.title";
    }

    @Override
    protected String getNoSelectionMessageKey() {
        return "pages.admin.legalHoliday.edit.noSelection";
    }

    @Override
    protected Panel getAddPanel(String panelId) {
        return new LegalHolidayPanel(panelId, getPageParameters(), new LegalHolidayUIModel());
    }

    @Override
    protected Panel getEditPanel(String panelId, LegalHoliday dbModel) {
        getPageParameters().clearNamed();
        return new LegalHolidayPanel(panelId, null, new LegalHolidayUIModel(dbModel));
    }

    @Override
    protected List<LegalHoliday> loadAvailableEntities() {
        LegalHolidayService service = TimeTrackingWebApplication.getService(LegalHolidayService.class);
        return service.getAllLegalHolidays();
    }

    protected String getCheckboxFilterLabel() {
        return "page.admin.legalHoliday.form.showOnlyCurrentYear";
    }

    protected boolean matchesCondition(LegalHoliday holiday) {
        int currentYear = Calendar.getInstance().get(Calendar.YEAR);
        return currentYear == holiday.getYear();
    }
}
